//
//  LoginViewController.swift
//  Swift_SendMessage
//
//  Created by lanou on 15/11/25.
//  Copyright © 2015年 changfengZhang. All rights reserved.
//

import UIKit

class LoginViewController: UIViewController {

    var userNameTextFiled : UITextField!
    
    var passWordTextFiled : UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.whiteColor()
        self.createView()
    }
    
    func createView() {
        
        //userName
        self.userNameTextFiled = UITextField(frame: CGRectMake(10, 50, self.view.frame.size.width - 20, 30))
        
        userNameTextFiled!.placeholder = "请输入用户名"
        
        userNameTextFiled!.textAlignment = NSTextAlignment.Center
        
        userNameTextFiled!.layer.cornerRadius = 3.0
        
        userNameTextFiled!.layer.borderWidth = 1.0
        
        self.view.addSubview(userNameTextFiled!)
        
        //passWord
        self.passWordTextFiled = UITextField(frame: CGRectMake(10, 130, self.view.frame.size.width - 20, 30))
        
        passWordTextFiled!.placeholder = "请输入密码"
        
        passWordTextFiled!.secureTextEntry = true
        
        passWordTextFiled!.textAlignment = NSTextAlignment.Center
        
        passWordTextFiled!.layer.cornerRadius = 3.0
        
        passWordTextFiled!.layer.borderWidth = 1.0
        
        self.view.addSubview(passWordTextFiled!)
        
        //loginButton
        let loginButton = UIButton(type: UIButtonType.Custom)
        
        loginButton.frame = CGRectMake(10, 210, self.view.frame.size.width - 20, 30)
        
        loginButton.setTitle("登录", forState: UIControlState.Normal)
        
        loginButton.addTarget(self, action: Selector("loginButtonClicked"), forControlEvents: UIControlEvents.TouchUpInside)
        
        loginButton.backgroundColor = UIColor.grayColor()
        
        self.view.addSubview(loginButton)
        
        //registerButton
        let registerButton = UIButton(type: UIButtonType.Custom)
        
        registerButton.frame = CGRectMake(self.view.frame.size.width - 60, 270, 50, 30)
        
        registerButton.setTitle("注册", forState: UIControlState.Normal)
        
        registerButton.addTarget(self, action: Selector("registerButtonClicked"), forControlEvents: UIControlEvents.TouchUpInside)
        
        registerButton.backgroundColor = UIColor.grayColor()
        
        self.view.addSubview(registerButton)
        
    }
    
    func loginButtonClicked() {
        
        let loginHp = LoginHelper()
        
        loginHp.loginWithUser(self.userNameTextFiled!.text!, passWord: self.passWordTextFiled.text!)
        
    }
    
    func registerButtonClicked() {
        
        let registerVC = RegisterViewController()
        
        self.presentViewController(registerVC, animated: true) { () -> Void in
            
        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
